ubuntu系统中jupyterhub安装R内核集成rstudio

您所在的位置:网站首页 jupyter hub和lab ubuntu系统中jupyterhub安装R内核集成rstudio

ubuntu系统中jupyterhub安装R内核集成rstudio

#ubuntu系统中jupyterhub安装R内核集成rstudio| 来源: 网络整理| 查看: 265

需求 :

最后公司需要将原来用的Jupyter单用户版本改成Jupyterhub多用户版本,方便公司统一管理用户,并且因为平时工作会用到python和R的IDE,正好Jupyterhub可以满足需求,网上搜了很多,基本是三种方式,一种是通过k8s部署安装(官方建议的,但太多坑,太难),一种是直接docker pull jupyterhub/jupyterhub配置启动,但是它是单用户的只能做为测试用,一种是在本地进行pip/conda安装(我用的是最后一种,不同的是,我将环境都装在了容器里)。

建议用户数量不超过50人

我是单机部署在docker容器中的,并打包成镜像,最终大小9.03G

首先准备环境:

1.我的服务器为centos (我电脑是windows系统,通过xshell连接公司服务器)

2.服务器上需要有docker(没有请自行安装)

第一步:

sudo docker pull ubuntu 下载一个ubuntu镜像,装在容器里以免破环我们服务器的环境

sudo docker run -p 8081:8000 -itd --name test_jupyterhub ubuntu /bin/bash 启动ubuntu镜像(会生成容器)

sudo docker ps 查看刚启动的容器 名为test_jupyterhub的,找到id号

进入容器中 第二步:

开始准备安装:

ubuntu自带apt-get安装源 因为后期安装R内核需要用到conda所以我们安装conda源及依赖nodejs

apt-get update apt-get upgrade apt-get install sudo apt-get install nodejs(nodejs -v如果没装成功请执行以下命令) sudo apt-get update sudo apt-get install curl curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh sudo bash nodesource_setup.sh sudo apt-get install nodejs nodejs -v 就会有版本信息出来 npm -v

安装conda , jupyterhub

这里我使用清华的镜像站点下载,速度很nice,50-60MB/s(conda有2和3版本,自行选择,我用的是3)

wgethttps://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.2.0-Linux-x86_64.sh bash Anaconda3-5.2.0-Linux-x86_64.sh

根据提示安装即可,安装过程中会询问你是否将anaconda的路径加入到环境变量.bashrc中,默认是no,所以如果在安装的过程中手太快,一键到底了的话,可以通过手动添加的方式进行设置

sudo apt-get install vim vim ~/.bashrc

在最后一行添加exportPATH="/root/anaconda3/bin:$PATH"

保存退出 source~/.bashrc 检测Anaconda是否安装成功:

conda list

(用conda安装的Jupyterhub需要给root 777权限,不然后面Jupyterhub启动不了)

condainstall -c conda-forge jupyterhub 或者 用 pip也行

pip3 install jupyterhub notebook -ihttps://pypi.douban.com/simple/

检查是否安装成功

jupyterhub -h npm install -g configurable-http-proxy configurable-http-proxy -h

然后生成配置文件 在/etc/jupyterhub目录下有个config文件

jupyterhub --generate-config-f/etc/jupyterhub/jupyterhub_config.py

修改配置

c.JupyterHub.ip ='0.0.0.0' c.JupyterHub.port =8000(docker run的时候有个端口8000就是此暴露端口) c.Spawner.ip ='127.0.0.1' c.PAMAuthenticator.encoding ='utf8' c.Authenticator.whitelist = {'admin'} c.LocalAuthenticator.create_system_users =True c.Authenticator.admin_users = {'admin'} c.JupyterHub.authenticator_class='dummyauthenticator.DummyAuthenticator' c.JupyterHub.statsd_prefix ='jupyterhub' c.Spawner.notebook_dir ='/home/spawner/' c.JupyterHub.statsd_prefix ='jupyterhub'

如果是root用户 需要修改源码 具体操作见下方链接

用户认证

pip3 install jupyterhub-dummyauthenticator -ihttps://pypi.douban.com/simple/

然后,如果遇到生成token问题,在配置文件中修改此配置:

c.JupyterHub.authenticator_class ='dummyauthenticator.DummyAuthenticator'

虽然我们设置了用户,但是并没有密码,所以要在系统设置密码

useradd admin passwd admin 输入两次密码即可登陆

启动jupyterhub

jupyterhub -f /etc/jupyterhub/jupyterhub_config.py

ctrl+c退出jupyterhub接下来安装R与Rstudio

安装R之前需要先将/root/anaconda/bin/python 随便改个名字然后把python3通过软链接 ln -s /root/anaconda/bin/python3 /root/anaconda/bin/python 因为jupyterhub是依赖python3的 默会找到Python2而且会对它进行升级,会出现BUG报错 No module name conda.cli

conda install -c r r-irkernel

安装rstudio请参照官网(安装到最后要选择区域,尽量选Asia亚州离中国近的)

接下来安装jupyter-rsession-proxy它可以集成rstudio

完成后再登陆会有个坑,就是多用户登陆的,但是只有第一个用户可以访问rstudio,其它用户不行,这是权限问题,要将/tmp/rstudio-server/secure-cookie-key 改成757权限 chmod 777 secure-cookie-key 好啦完成啦,虽然写的简单,但是对于小白的我来说,自己看官网和技术贴也是弄了3周,才解决所有的坑

以下是参考的贴子 和官方文档

https://www.jianshu.com/p/fd9ddce53465 这个贴子和下面的贴子互补

https://blog.51cto.com/m51cto/2370679 这个贴子很详细

https://github.com/jupyterhub/jupyter-rsession-proxy 这是github上的具体安装方法

https://www.rstudio.com/products/rstudio/download-server/ 这是安装rstudio的

http://cran.rstudio.com/bin/linux/ubuntu/README.html 这是安装R依赖包



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3